package com.webSite.demo.cy.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.webSite.demo.cy.bean.HomeMeta;
import com.webSite.demo.cy.mapper.HomeMetaMapper;

@Controller
@EnableAutoConfiguration
public class HomeMetaController {

	@Autowired
	HomeMetaMapper homeMetaMapper;
	
	@RequestMapping("/homeMeta.html")
    String homeMeta(Model model) {
		List<HomeMeta> list = homeMetaMapper.findAllInfo();
		if(!list.isEmpty()) {
			model.addAttribute("list", list);
		}
        return "admin/homeMeta";  
    }
	
	@RequestMapping("/addHomeMeta.html")
	public String addHomeMeta(HomeMeta homeMeta) {
		homeMeta.setCreated(new Date());
		homeMeta.setUpdated(new Date());
		homeMeta.setState(1);
		homeMetaMapper.insertHomeMeta(homeMeta);
		return "redirect:/homeMeta.html";
	}
	
	@RequestMapping("/deleteMeta.html")
	public String deleteMeta(int id) {
		homeMetaMapper.updateState(id);
		return "redirect:/homeMeta.html";
	}
	
}
